package com.blinddate.controller;

import com.blinddate.pojo.result.Result;
import com.blinddate.pojo.vo.UserInfVO;
import com.blinddate.service.InterestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/interest")
@Slf4j
@Api(tags = "用户收藏相关接口")
public class InterestController {
    @Autowired
    private InterestService interestService;

    @PostMapping
    @ApiOperation("添加收藏")
    public Result AddInterest(@RequestParam Long userid){
        log.info("收藏用户:{}",userid);
        Boolean interestBool = interestService.add(userid);
        if (interestBool == false){
            return Result.error("已经有该收藏或该用户不存在请刷新重新查看");
        }
        return Result.success("添加成功");

    }
    @GetMapping("/list")
    @ApiOperation("展示收藏列表")
    public Result list(@RequestParam Integer page,@RequestParam Integer size){
        log.info("展示收藏列表，参数page:{},size:{}",page,size);
        List<UserInfVO> list = interestService.list(page, size);
        if (list==null){
            return Result.error("获取列表失败你的关注列表可能出了问题，请联系工作人员查看你的信息");
        }
        if (list.size()==0){
            return Result.error("未关注过其他人");
        }
        return Result.success(list);
    }
    @DeleteMapping
    @ApiOperation("取消收藏")
    public Result delete(@RequestParam Long userid){
        log.info("取消收藏用户:{}",userid);
        interestService.delete(userid);
        return Result.success("取消成功");
    }

    @GetMapping("/who_interest_list")
    @ApiOperation("展示谁收藏了我")
    public Result<List<UserInfVO>> whoInterestList(@RequestParam Integer page,@RequestParam Integer size){
        log.info("展示谁收藏了我，参数page:{},size:{}",page,size);
        List<UserInfVO> userInfVOS = interestService.whoInterestList(page, size);
        if (userInfVOS==null){
            return Result.error("获取列表失败，请联系工作人员查看你的信息");
        }
        if (userInfVOS.size()==0){
            return Result.error("未有人关注过你");
        }
        return Result.success(userInfVOS);
    }

}
